export default function getData({ oldData }) {
  const tseslintImporter = {
    id: 'tseslint',
    importer: "import tseslint from 'typescript-eslint'",
  }
  const files = {
    id: 'files',
    config: "{files: ['**/*.{js,mjs,cjs,ts,vue}']},",
  }
  const tseslintConfig = {
    id: 'tseslint',
    config: '...tseslint.configs.recommended,',
  }
  const vueTsParserConfig = {
    id: 'vueTsParser',
    config: "{files: ['**/*.vue'], languageOptions: {parserOptions: {parser: tseslint.parser}}},",
  }

  const importerList = oldData.importerList.flatMap((importItem) => {
    return importItem.id === 'pluginVue' ? [tseslintImporter, importItem] : importItem
  })
  const configList = oldData.configList.flatMap((configItem) => {
    if (configItem.id === files.id) {
      configItem.config = files.config
      return configItem
    }
    if (configItem.id === 'pluginVue') {
      return [tseslintConfig, configItem, vueTsParserConfig]
    }
    return configItem
  })
  const data = {
    importerList,
    configList,
  }
  return data
}
